﻿Type=Activity
Version=6
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Type onebyoneitem(id As String,stype As String,name As String,price_lssm As String,price_xssm As String,price_xsdz As String,status As String)
	Type bankeitem(id As String,hours As String,name As String,starttime As String,price As String,bmstatus As String,address As String,status As String,kc_end_time As String,shiduanlst As List)
	Type kcobj(ntype As Int,oi As onebyoneitem,bi As bankeitem)
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Private curtecid As Int
	Private ulv As UltimateListView
	Private lstdata1,lstdata2 As List
	Private btnleft As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim telaw As telanywhere
telaw.Initialize(Activity)

	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("layallkclistbyteacher")
	initviews
End Sub
Private Sub initviews
	curtecid=g_store.conf.Get("tecid")
	comm.setFA(btnleft,"fa-angle-left","")
	Dim nSectionH As Int=70dip,nOnebyoneH As Int=90dip,nFudaobanH As Int=270dip
	Dim cd As ColorDrawable
	cd.Initialize(0xFFEFEFEF,0)
	ulv.DividerDrawable=cd
	ulv.DividerHeight=1dip
	ulv.AddLayout("itemsectionheader","ui_LayoutCreator","sectionheader_ContentFiller",nSectionH,False)
	ulv.AddLayout("itemteacherkcall","ui_LayoutCreator","onebyone_ContentFiller",nOnebyoneH,True)
	ulv.AddLayout("itemfudaoban","ui_LayoutCreator","fudaobanitem_ContentFiller",nFudaobanH,True)
	ulv.AddSection("onebyone","itemsectionheader","itemteacherkcall","itemsectionheader")
	ulv.SetSectionHeader(1,"onebyone")
	ulv.AddSection("fudanban","itemsectionheader","itemfudaoban","itemsectionheader")
	ulv.SetSectionHeader(2,"fudanban")
	'ulv.AddSection("fudanbanover","itemsectionheader","itemfudaoban","itemsectionheader")
	lstdata1.Initialize
	lstdata2.Initialize
	reqKcLstByTecId(curtecid)
End Sub
Sub reqKcLstByTecId(tecid As Int)
	comm.showProgress("正在获取列表")
	ParseHelper.doGetReq(Me,"kclsttec",comm.getApi(comm.apiIdx.REQALLKCLISTBYTEACHER),Array As String("js_id",tecid,"size",999))
	
End Sub
Sub parseKC(str As String)
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim data As List = root.Get("data") 
	lstdata1.Clear
	lstdata2.Clear
	DateTime.DateFormat="yyyy-MM-dd"
	For Each coldata As Map In data 
	    Dim kc_end_time As String = coldata.Get("kc_end_time") 
	    Dim is_youhui As String = coldata.Get("is_youhui") 
	    Dim kc_title As String = coldata.Get("kc_title") 
	    Dim kc_num As String = coldata.Get("kc_num") 
	    Dim shiduan As List = coldata.Get("shiduan") 
	    Dim bm_person As String = coldata.Get("bm_person") 
	    Dim kc_mode As String = coldata.Get("kc_mode") 
	    Dim kc_grade As String = coldata.Get("kc_grade") 
	    Dim kc_money_st As String = coldata.Get("kc_money_st") 
		Dim kc_money As String = coldata.Get("kc_money")
		Dim kc_money_bk As String = coldata.Get("kc_money_bk")
	    Dim addtime As String = coldata.Get("addtime") 
	    Dim js_id As String = coldata.Get("js_id") 
	    Dim kc_type As String = coldata.Get("kc_type") 
	    Dim id As String = coldata.Get("id") 
	    Dim kc_address As String = coldata.Get("kc_address") 
	    Dim kc_hour As String = coldata.Get("kc_hour") 
	    Dim status As String = coldata.Get("status") 
		If kc_type.EqualsIgnoreCase("一对一") Or kc_type.EqualsIgnoreCase("试听课") Then
			Dim ooi As onebyoneitem
			ooi.Initialize
			ooi.id=id
			ooi.name=kc_title
			ooi.price_xssm=kc_money_st
			ooi.price_lssm=kc_money
			ooi.price_xsdz=kc_money_bk
			ooi.stype=kc_type
			ulv.AddItemToSection(lstdata1.Size,"onebyone")
			lstdata1.Add(ooi)
			Log("add 1v1")
		Else if kc_type.EqualsIgnoreCase("班课") Then
			Dim bki As bankeitem
			bki.Initialize
			bki.id=id
			bki.shiduanlst=shiduan
			bki.address=kc_address
			bki.bmstatus=$"总人数:${kc_num} 已报名:${bm_person}"$
			bki.name=kc_title
			bki.price=kc_money_bk
			bki.hours=kc_hour
			bki.starttime=addtime
			bki.kc_end_time=kc_end_time
			Dim st1 As Long=DateTime.DateParse(kc_end_time)
			If st1>DateTime.Now And bm_person<kc_num Then
				bki.status="进行中"
			Else
				bki.status="已结束"
			End If	
			ulv.AddItemToSection(lstdata2.Size,"fudanban")
			lstdata2.Add(bki)
			Log("add banke")
		End If
		
	Next 
	Dim status As String = root.Get("status") 

End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		Dim str As String=thj.GetString
		Dim nr As netRes=ParseHelper.getStatusData(str)
		If nr.nCode=200 Then
			Select thj.JobName
			Case "kclsttec"
				parseKC(str)
			End Select
			
		Else
			comm.TL("错误:"&nr.sData)
		End If
	Else
		comm.TL("网络错误:"&thj.JobName&thj.ErrorMessage)
	End If
	thj.Release
End Sub
Sub ui_LayoutCreator(LayoutName As String, LayoutPanel As Panel)
	LayoutPanel.LoadLayout(LayoutName)
End Sub
Sub sectionheader_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim lbl As Label=LayoutPanel.GetView(0)
	Select ItemID
	Case 1
		 lbl.Text="一对一"
	Case 2
		lbl.Text="班课"
	End Select
	lbl.Gravity=Gravity.CENTER
	lbl.Color=0xffEFEFEF

End Sub
Sub onebyone_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim ooi As onebyoneitem=lstdata1.Get(ItemID)
	Dim p As Panel=LayoutPanel.GetView(0)
	Dim kcname As Label=p.GetView(1)
	kcname.Text=ooi.name
	If	ooi.stype.EqualsIgnoreCase("试听课") Then
		kcname.Text=kcname.Text&"(试听课)"
	End If
	
	Dim price As Label=p.GetView(2)
	price.Text=ooi.price_lssm
	Dim kcobj As kcobj
	kcobj.Initialize
	kcobj.ntype=1
	kcobj.oi=ooi
	LayoutPanel.Tag=kcobj
End Sub
Sub fudaobanitem_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim bki As bankeitem=lstdata2.Get(ItemID)
	Dim kcobj As kcobj
	kcobj.Initialize
	kcobj.ntype=2
	kcobj.bi=bki
	LayoutPanel.Tag=kcobj
	Dim p As Panel=LayoutPanel.GetView(0)
	Dim title As Label=p.GetView(0)
	title.Text=bki.name
	Dim starttime As Label=p.GetView(2)
	starttime.Text=bki.starttime
	Dim price As Label=p.GetView(4)
	price.Text=bki.price
	Dim hours As Label=p.GetView(5)
	hours.Text="共"&bki.hours&"小时"
	Dim bmstatus As Label=p.GetView(6)
	bmstatus.Text=bki.bmstatus
	Dim address As Label=p.GetView(9)
	address.Text=bki.address
	Dim lblbm As Label=p.GetView(10)
	Dim cd As ColorDrawable
	If bki.status.EqualsIgnoreCase("已结束") Then
		cd.Initialize2(Colors.Gray,5dip,0,comm.N_COLOR_TITLE)
		lblbm.Enabled=False
	Else		
		cd.Initialize2(comm.N_COLOR_TITLE,5dip,0,comm.N_COLOR_TITLE)
		lblbm.Enabled=True
	End If
	lblbm.Background=cd
End Sub

Sub ulv_ItemClick(ItemID As Long, Position As Int, ClickedPanel As Panel)
	Dim oo As kcobj=ClickedPanel.Tag
	Dim kci As kcItem
	kci.Initialize
	Log(oo.ntype)
	Select oo.ntype
	Case 1
		Dim oi As onebyoneitem=oo.oi
		Log(oi)
		kci.kcid=oi.id
		kci.kctitle=oi.name
		If oi.stype.EqualsIgnoreCase("试听课") Then
			kci.kctype=1
		Else
			kci.kctype=2
		End If
		kci.price_lssm=oi.price_lssm
		kci.price_xssm=oi.price_xssm
	Case 2
		Dim bi As bankeitem=oo.bi
		Log(bi)
		kci.kcid=bi.id
		kci.kctitle=bi.name
		kci.price_xsdz=bi.price
		kci.addr=bi.address
		kci.kctype=3
		kci.hours=bi.hours
		kci.shiduanlst=bi.shiduanlst
	End Select
	Log("ulv_ItemClick:"&ItemID)
	If kci.shiduanlst.IsInitialized=False Then kci.shiduanlst.Initialize 'list不能为空
	g_store.put("curkc",kci)
	If kci.kctype.EqualsIgnoreCase("3") Then
		StartActivity(actBuyFudanKC)
	Else
		StartActivity(actBuy1v1Kc)
	End If
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ivback_Click
	Activity.Finish
End Sub
